#include "sylar/logger.h"
#include <iostream>
#include <stdio.h>


using namespace std;
int main(){
    /*
    %m for message content
    %p for level
    %r for time after program start
    %c for logger name
    %t for thread id
    %n for \n
    %f for filename
    %l for line
    */
    sylar::Logger logger;
    auto appender_ptr = sylar::StdoutLogAppender::smart_ptr(new sylar::StdoutLogAppender());
    auto formatter_ptr = sylar::LogFormatter::smart_ptr(new sylar::LogFormatter("%r thread:%t  %f %l [%p]: %m"));
    appender_ptr->setFormatter(formatter_ptr);

    auto file_appender_ptr = sylar::FileLogAppender::smart_ptr(new sylar::FileLogAppender("/home/xie/sylar/test.log"));
    file_appender_ptr->setFormatter(formatter_ptr);

    logger.addAppender(appender_ptr);
    logger.addAppender(file_appender_ptr);

    string s = string("This is a message");
    auto i = new sylar::LogEvent(sylar::LogLevel::FATAL, __FILE__, __LINE__, gettid(), -1, clock(), s);
    auto event_ptr = sylar::LogEvent::smart_ptr(i);
    logger.info(event_ptr);
    logger.debug(event_ptr);
    logger.warn(event_ptr);
    logger.error(event_ptr);
    logger.fatal(event_ptr);
}
